package com.zmn.plat.services.impl.base.acceptproject;

import com.zmn.account.common.utils.NumberUtil;
import com.zmn.common.constant.GlobalConsts;
import com.zmn.common.utils.date.DateUtil;
import com.zmn.plat.model.entity.base.acceptproject.AcceptProject;
import com.zmn.plat.model.entity.base.acceptproject.AcceptProjectQuery;
import com.zmn.plat.persistence.interfaces.base.acceptproject.AcceptProjectDao;
import com.zmn.plat.services.interfaces.base.acceptproject.AcceptProjectService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * 描述: 验收项目接口实现类
 *
 * @author fengxuecai
 * @since 2021/11/17 14:19
 */
@Slf4j
@Service
public class AcceptProjectServiceImpl implements AcceptProjectService {

    private static final String TAG = "验收项目基础服务接口";

    @Resource
    private AcceptProjectDao baseAcceptProjectDao;

    @Override
    public AcceptProject findById(Integer acceId) {

        if (NumberUtil.isNullOrZero(acceId)) {
            log.error("[{}],根据id查询数据acceId为null", TAG);
            return null;
        }
        return baseAcceptProjectDao.findById(acceId);
    }

    @Override
    public Integer findMaxSort() {
        return baseAcceptProjectDao.findMaxSort();
    }

    @Override
    public List<AcceptProject> listByIds(List<Integer> acceIds) {

        if (CollectionUtils.isEmpty(acceIds)) {
            log.error("[{}],按条件查询数据,acceIds为null", TAG);
            return null;
        }
        return baseAcceptProjectDao.listByIds(acceIds);
    }

    @Override
    public List<AcceptProject> listByQuery(AcceptProjectQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return null;
        }
        return baseAcceptProjectDao.listByQuery(query);
    }

    @Override
    public List<AcceptProject> listPageByQuery(AcceptProjectQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return null;
        }
        query.setTotalCount(countByQuery(query));
        return baseAcceptProjectDao.listPageByQuery(query);
    }

    @Override
    public Integer countByQuery(AcceptProjectQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件统计数据,query为null", TAG);
            return null;
        }
        return baseAcceptProjectDao.countByQuery(query);
    }

    @Override
    public Integer updateByKey(AcceptProject baseAcceptProject) {

        if (Objects.isNull(baseAcceptProject.getAcceId())) {
            log.error("[{}],根据id修改数据,baseAcceptProject为null", TAG);
            return null;
        }
        return baseAcceptProjectDao.updateByKey(baseAcceptProject);
    }

    @Override
    public void updateStatusBatch(List<Integer> ids, Integer status, String operator) {

        if (!Objects.equals(status, GlobalConsts.NO) && !Objects.equals(status, GlobalConsts.YES)) {
            log.error("[{}],status状态超出取值范围", TAG);
            return;
        }
        baseAcceptProjectDao.updateStatusBatch(ids, status, operator, DateUtil.getNow());
    }

    @Override
    public Integer insert(AcceptProject baseAcceptProject) {

        if (Objects.isNull(baseAcceptProject)) {
            log.error("[{}],新增数据,baseAcceptProject为null", TAG);
            return null;
        }
        return baseAcceptProjectDao.insert(baseAcceptProject);
    }

    @Override
    public void insertBatch(List<AcceptProject> list) {

        if (CollectionUtils.isEmpty(list)) {
            log.error("[{}],数据为空", TAG);
            return;
        }
        baseAcceptProjectDao.insertBatch(list);
    }

    @Override
    public void insertBatchExport(List<AcceptProject> list) {

        if (CollectionUtils.isEmpty(list)) {
            log.error("[{}],数据为空", TAG);
            return;
        }
        baseAcceptProjectDao.insertBatchExport(list);
    }

    @Override
    public Integer deleteByKey(Integer acceId) {

        if (Objects.isNull(acceId)) {
            log.error("[{}],根据id删除数据,acceId为null", TAG);
            return null;
        }
        return baseAcceptProjectDao.deleteByKey(acceId);
    }

}